"""
多线程之间共享全局变量
"""
from threading import Thread
import time
# 定义一个全局变量
g_num = 100


def work1():
    num = 1
    global g_num
    for i in range(3):
        g_num += 1
        print("---子线程1---work1函数---g_num:%d" % g_num)


def work2():
    num = 2
    global g_num
    print("\t---子线程2---work2函数---个g_num:%d" % g_num)


if __name__ == "__main__":
    print("启动线程之前：g_num:%d" % g_num)

    t1 = Thread(target=work1)

    t2 = Thread(target=work2)

    t1.start()  # 主线程，t1线程

    time.sleep(1)
    t2.start() # 主线程，t1线程，t2线程